from gtts import gTTS
from gtts import gTTSError
from playsound import playsound
from tempfile import NamedTemporaryFile

class TextReader():


    def say(self,text,lang='zh-CN') -> None:
        voice = NamedTemporaryFile()
        try:
            gTTS(text=text, lang=lang).write_to_fp(voice)
        except gTTSError:
            print(gTTSError)
        # playsound(voice.name)
        playsound(voice.name, block=False)
        voice.close()




